<template>
  <div id="app">
    <h1>反馈管理系统</h1>
    <!-- 反馈添加表单 -->
    <form @submit.prevent="addFeedback">
      <label for="name">反馈人姓名：</label>
      <input
          type="text"
          id="name"
          v-model="newFeedback.name"
          placeholder="请输入姓名"
          required
      />
      <label for="content">反馈内容：</label>
      <textarea
          id="content"
          v-model="newFeedback.content"
          placeholder="请输入反馈内容"
          required
      ></textarea>
      <label for="contact">联系方式：</label>
      <input
          type="text"
          id="contact"
          v-model="newFeedback.contact"
          placeholder="请输入联系方式"
          required
      />
      <button type="submit">提交反馈</button>
    </form>
    <!-- 反馈列表展示 -->
    <ul>
      <li v-for="(feedback, index) in feedbacks" :key="index">
        <p>反馈人：{{ feedback.name }}</p>
        <p>反馈内容：{{ feedback.content }}</p>
        <p>联系方式：{{ feedback.contact }}</p>
        <button @click="deleteFeedback(index)">删除反馈</button>
      </li>
    </ul>
  </div>
</template>

<script setup>
import { ref } from 'vue';

// 定义反馈列表的响应式数据
const feedbacks = ref([]);
// 定义新反馈信息的响应式数据
const newFeedback = ref({
  name: '',
  content: '',
  contact: ''
});

// 添加反馈的方法
const addFeedback = () => {
  if (
      newFeedback.value.name.trim()!== '' &&
      newFeedback.value.content.trim()!== '' &&
      newFeedback.value.contact.trim()!== ''
  ) {
    feedbacks.value.push({...newFeedback.value });
    // 清空表单
    newFeedback.value = {
      name: '',
      content: '',
      contact: ''
    };
  }
};

// 删除反馈的方法
const deleteFeedback = (index) => {
  feedbacks.value.splice(index, 1);
};
</script>

<style scoped>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}

form {
  margin-bottom: 20px;
}

label {
  display: block;
  margin-bottom: 5px;
}

input,
textarea {
  width: 300px;
  padding: 8px;
  margin-bottom: 10px;
}

button {
  padding: 8px 16px;
  background-color: #42b983;
  color: white;
  border: none;
  cursor: pointer;
}

button:hover {
  background-color: #357a5e;
}

ul {
  list-style-type: none;
  padding: 0;
}

li {
  border: 1px solid #ddd;
  padding: 10px;
  margin-bottom: 10px;
}
</style>